/*
 * adminMain.java
 *
 * Created on 1. März 2008, 08:40
 */

package com.googlecode.oskis.admin;
import com.googlecode.oskis.library.db.PGConnection;
import com.googlecode.oskis.library.security.CryptedPasswd;
import javax.swing.JOptionPane;
import java.sql.*;


/**
 *
 * @author  thomas
 */
public class adminMain extends javax.swing.JFrame {
    
    
    private Connection db;
    
    /** Creates new form adminMain */
    public adminMain() {
        initComponents();
        db=new PGConnection("localhost","oskisdb","postgres","postgres").getConnection();
        if (db==null) {
            JOptionPane.showMessageDialog(this,"Keine Verbindung zu Datenbank");
            System.exit(1);
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        txtTest = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        txtSalt = new javax.swing.JTextField();
        mnuAdmin = new javax.swing.JMenuBar();
        mnuDatei = new javax.swing.JMenu();
        mnuTools = new javax.swing.JMenu();
        mitReadSQLScript = new javax.swing.JMenuItem();
        mitCreateSQL = new javax.swing.JMenuItem();
        mnuStamm = new javax.swing.JMenu();
        mnuMiscStamm = new javax.swing.JMenu();
        mitAnrede = new javax.swing.JMenuItem();
        mitSex = new javax.swing.JMenuItem();
        mitLand = new javax.swing.JMenuItem();
        mitTitel = new javax.swing.JMenuItem();
        mnuEinrichtungsstamm = new javax.swing.JMenu();
        mitUsers = new javax.swing.JMenuItem();
        mitEinrichtungen = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        mitPersonalstamm = new javax.swing.JMenuItem();
        mnuSystem = new javax.swing.JMenu();
        mitSNO = new javax.swing.JMenuItem();
        mitParamKat = new javax.swing.JMenuItem();
        mitParams = new javax.swing.JMenuItem();
        mitEnde = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("OSKIS Admin");

        jButton1.setText("test md5");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        mnuDatei.setText("Datei");

        mnuTools.setText("Tools");

        mitReadSQLScript.setText("SQL Script lesen");
        mitReadSQLScript.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mitReadSQLScriptActionPerformed(evt);
            }
        });
        mnuTools.add(mitReadSQLScript);

        mitCreateSQL.setText("SQL Script erzeugen");
        mitCreateSQL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mitCreateSQLActionPerformed(evt);
            }
        });
        mnuTools.add(mitCreateSQL);

        mnuDatei.add(mnuTools);

        mnuStamm.setText("Stammdaten");

        mnuMiscStamm.setText("Grundlegende Stammdaten");

        mitAnrede.setText("Anreden");
        mitAnrede.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mitAnredeActionPerformed(evt);
            }
        });
        mnuMiscStamm.add(mitAnrede);

        mitSex.setText("Geschlechter");
        mitSex.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mitSexActionPerformed(evt);
            }
        });
        mnuMiscStamm.add(mitSex);

        mitLand.setText("Länder");
        mitLand.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mitLandActionPerformed(evt);
            }
        });
        mnuMiscStamm.add(mitLand);

        mitTitel.setText("Titel");
        mitTitel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mitTitelActionPerformed(evt);
            }
        });
        mnuMiscStamm.add(mitTitel);

        mnuStamm.add(mnuMiscStamm);

        mnuEinrichtungsstamm.setText("Einrichtung");

        mitUsers.setText("Benutzer");
        mitUsers.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mitUsersActionPerformed(evt);
            }
        });
        mnuEinrichtungsstamm.add(mitUsers);

        mitEinrichtungen.setText("Einrichtungen");
        mitEinrichtungen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mitEinrichtungenActionPerformed(evt);
            }
        });
        mnuEinrichtungsstamm.add(mitEinrichtungen);

        jMenuItem1.setText("Organisationseinheiten");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        mnuEinrichtungsstamm.add(jMenuItem1);

        mitPersonalstamm.setText("Personalstamm");
        mitPersonalstamm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mitPersonalstammActionPerformed(evt);
            }
        });
        mnuEinrichtungsstamm.add(mitPersonalstamm);

        mnuStamm.add(mnuEinrichtungsstamm);

        mnuSystem.setText("System");

        mitSNO.setText("Laufende Nummern");
        mnuSystem.add(mitSNO);

        mitParamKat.setText("Parameter Kategorien");
        mitParamKat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mitParamKatActionPerformed(evt);
            }
        });
        mnuSystem.add(mitParamKat);

        mitParams.setText("Systemparameter");
        mitParams.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mitParamsActionPerformed(evt);
            }
        });
        mnuSystem.add(mitParams);

        mnuStamm.add(mnuSystem);

        mnuDatei.add(mnuStamm);

        mitEnde.setText("Ende");
        mitEnde.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mitEndeActionPerformed(evt);
            }
        });
        mnuDatei.add(mitEnde);

        mnuAdmin.add(mnuDatei);

        setJMenuBar(mnuAdmin);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtSalt, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txtTest, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)))
                .addContainerGap(42, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtTest, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtSalt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(219, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mitEndeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mitEndeActionPerformed
        System.exit(0);
    }//GEN-LAST:event_mitEndeActionPerformed

    private void mitReadSQLScriptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mitReadSQLScriptActionPerformed
        frmSQLScriptReader f=new frmSQLScriptReader(db);
        f.setVisible(true);
    }//GEN-LAST:event_mitReadSQLScriptActionPerformed

    private void mitAnredeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mitAnredeActionPerformed
        new frmSimpleTableEdit(db,"xanrede","anrede","Anrede").setVisible(true);
    }//GEN-LAST:event_mitAnredeActionPerformed

    private void mitSexActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mitSexActionPerformed
        new frmSimpleTableEdit(db,"xgeschlecht","geschlecht","Geschlecht").setVisible(true);
    }//GEN-LAST:event_mitSexActionPerformed

    private void mitCreateSQLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mitCreateSQLActionPerformed
        new frmSQLMaker().setVisible(true);
    }//GEN-LAST:event_mitCreateSQLActionPerformed

    private void mitTitelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mitTitelActionPerformed
        new frmSimpleTableEdit(db,"xtitel","titel","Titel").setVisible(true);
    }//GEN-LAST:event_mitTitelActionPerformed

    private void mitLandActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mitLandActionPerformed
        new frmSimpleTableEdit(db,"xland","land","Land").setVisible(true);
}//GEN-LAST:event_mitLandActionPerformed

    private void mitPersonalstammActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mitPersonalstammActionPerformed
        new frmPersonalStamm(db).setVisible(true);
    }//GEN-LAST:event_mitPersonalstammActionPerformed

    private void mitEinrichtungenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mitEinrichtungenActionPerformed
        new frmEinrichtungenStamm(db).setVisible(true);
    }//GEN-LAST:event_mitEinrichtungenActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String pwd=txtTest.getText();
        CryptedPasswd m=new CryptedPasswd(pwd,txtSalt.getText());
        System.out.println(m.getEncryptedPasswd());
    }//GEN-LAST:event_jButton1ActionPerformed

    private void mitUsersActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mitUsersActionPerformed
        new frmUsers(db).setVisible(true);
    }//GEN-LAST:event_mitUsersActionPerformed

    private void mitParamKatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mitParamKatActionPerformed
        new frmSimpleTableEdit(db,"sparamkat","kategorie","kategorie").setVisible(true);
    }//GEN-LAST:event_mitParamKatActionPerformed

    private void mitParamsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mitParamsActionPerformed
        new frmSystemparams(db).setVisible(true);
    }//GEN-LAST:event_mitParamsActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        new frmOE(db).setVisible(true);
    }//GEN-LAST:event_jMenuItem1ActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new adminMain().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem mitAnrede;
    private javax.swing.JMenuItem mitCreateSQL;
    private javax.swing.JMenuItem mitEinrichtungen;
    private javax.swing.JMenuItem mitEnde;
    private javax.swing.JMenuItem mitLand;
    private javax.swing.JMenuItem mitParamKat;
    private javax.swing.JMenuItem mitParams;
    private javax.swing.JMenuItem mitPersonalstamm;
    private javax.swing.JMenuItem mitReadSQLScript;
    private javax.swing.JMenuItem mitSNO;
    private javax.swing.JMenuItem mitSex;
    private javax.swing.JMenuItem mitTitel;
    private javax.swing.JMenuItem mitUsers;
    private javax.swing.JMenuBar mnuAdmin;
    private javax.swing.JMenu mnuDatei;
    private javax.swing.JMenu mnuEinrichtungsstamm;
    private javax.swing.JMenu mnuMiscStamm;
    private javax.swing.JMenu mnuStamm;
    private javax.swing.JMenu mnuSystem;
    private javax.swing.JMenu mnuTools;
    private javax.swing.JTextField txtSalt;
    private javax.swing.JTextField txtTest;
    // End of variables declaration//GEN-END:variables
    
}
